package io.renren.modules.file.controller;

import java.util.Arrays;
import java.util.Map;

import io.renren.common.validator.ValidatorUtils;
import io.renren.modules.sys.shiro.ShiroUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import io.renren.modules.file.entity.OperLogEntity;
import io.renren.modules.file.service.OperLogService;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.R;



/**
 * 文件操作日志
 *
 * @author cheng
 * @email 751018031@qq.com
 * @date 2019-06-13 16:19:05
 */
@RestController
@RequestMapping("file/operlog")
public class OperLogController {
    @Autowired
    private OperLogService operLogService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("file:operlog:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = operLogService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    @RequiresPermissions("file:operlog:info")
    public R info(@PathVariable("id") Long id){
        OperLogEntity operLog = operLogService.getById(id);

        return R.ok().put("operLog", operLog);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("file:operlog:save")
    public R save(@RequestBody OperLogEntity operLog){
        operLog.setOperUserId(ShiroUtils.getUserId());
        operLogService.save(operLog);
        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("file:operlog:update")
    public R update(@RequestBody OperLogEntity operLog){
        ValidatorUtils.validateEntity(operLog);
        operLogService.updateById(operLog);
        
        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("file:operlog:delete")
    public R delete(@RequestBody Long[] ids){
        operLogService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

}
